<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Models extends BaseModel
{
    use HasFactory;
    protected $table = 'model';
    protected $primaryKey='modelid';
    // 允许批量操作的字段
    protected $fillable = ['modelname','tabelname','setting'];

    public function scopeSearch($query,$params)
    {
        if(!empty($params['midelid'])){
            $query->where('modelid',$params['modelid']);
        }
        if(!empty($params['type'])){
            if($params['type'] == 1){
                $query->where('pid',0);
            }else{
                $query->where('pid','<>',0);
            }

        }
        if(!empty($params['pid'])){
            $query->where('pid',$params['pid']);
        }
        return $query;
    }

    public function product(){
        return $this->hasMany(Product::class,'modelid');
    }


}
